package IOStreamStudy.bufferStreamCopy;

import java.io.*;

/**
 * 用BufferedStream字节流对图片,视频等二进制文件进行复制
 * */
public class BufferStreamCopyDemo {
    public static void main(String[] args) throws IOException {
        String imgPath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\bufferStreamCopy\\a.jpg";
        String copyPath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\bufferStreamCopy\\copy.jpg";

        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(imgPath));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(copyPath));
        byte[] buffer = new byte[1024];
        int len;
        while ((len = bufferedInputStream.read(buffer))!=-1){
            bufferedOutputStream.write(buffer,0,len);
        }
        System.out.println("copy完成");
        // 不关闭会导致文件错误
        bufferedOutputStream.close();
        bufferedInputStream.close();
    }
}
